package com.ftg.learn.chapter06.controller;

import com.alibaba.fastjson2.JSON;
import com.ftg.learn.chapter06.service.IStudentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * ResponseBody  : 把list这样的集合转换成为 json字符串
 *
 * @author kangjx
 * @createTime 2022/11/8
 */
@RestController
public class DemoController {

    @Resource
    IStudentService iStudentService;


    @GetMapping(value = "/hello1",produces = "application/json;charset=utf-8")
    @ResponseBody
    public List<Map<String,Object>> Hello1(){
        List<Map<String,Object>> list = iStudentService.showAll();
        return list;
    }

    /**
     * @responseBody 失效了
     * @return
     */
    @GetMapping(value = "/hello",produces = "application/json;charset=utf-8")
    public String Hello(){
        List<Map<String,Object>> list = iStudentService.showAll();
        return JSON.toJSONString(list);
    }

}
